﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ResUma
{
    public partial class SpecialitatiFrm : FrmRezumat
    {
        private Int32 PersoaneID;
        private String NumePersoana;
        public SpecialitatiFrm(ModuleClass mInfo,Int32 _PersoaneId,String _nume)
            : base(mInfo)
        {
            InitializeComponent();
            workConnString = mInfo.workConnectionString;
            PersoaneID = _PersoaneId;
            NumePersoana = _nume;
            this.Text = this.Text + " - " + NumePersoana;

            eSRPDataSet.SpecialitatiPersoane.IdPersoanaColumn.DefaultValue = PersoaneID;
            eSRPDataSet.SpecialitatiPersoane.PrincipalaColumn.DefaultValue = false;
            specialitatiDGV.m_AutoCompletionColumns.Add(iDSpecialitateColumn);
        }

        private void SpecialitatiFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.tipSpecialitatiTableAdapter.Connection = con;
            this.tipSpecialitatiTableAdapter.Fill(this.eSRPDataSet.TipSpecialitati);
            this.specialitatiPersoaneTableAdapter.Connection = con;
            this.specialitatiPersoaneTableAdapter.FillByIDPersoana(eSRPDataSet.SpecialitatiPersoane, PersoaneID);
            InchideConexiune(con);

            AddBindingSource(specialitatiPersoaneBindingSource);
            listTableAdaptor.Add(specialitatiPersoaneTableAdapter.Adapter);

        }

        private void specialitatiDGV_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == dataObtinereColumn.Index)
            {
                DateTime dataO = Convert.ToDateTime(specialitatiDGV[e.ColumnIndex, e.RowIndex].EditedFormattedValue);
                int luni = (int)DateTime.Now.Year * 12 + (int)DateTime.Now.Month - dataO.Year * 12 - dataO.Month;
                if (specialitatiDGV[luniVechimeDataGridViewTextBoxColumn.Index, e.RowIndex].Value == null)
                    return;
                if (specialitatiDGV[luniVechimeDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString() == String.Empty
                    || specialitatiDGV[luniVechimeDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString() == "0")
                    specialitatiDGV[luniVechimeDataGridViewTextBoxColumn.Index, e.RowIndex].Value = luni;

            }
        }
    }
}
